package com.accesshollywood.grfxOrdering.basics;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import javax.swing.DefaultComboBoxModel;

import com.accesshollywood.SQL.GFXSQL;
import com.accesshollywood.indexables.ShowName;

public class ShowNames {
	public static HashMap<Integer, ShowName> allShowNames;
	public static DefaultComboBoxModel showNames;

	public static void populateShowNames() {
		allShowNames = new HashMap<Integer, ShowName>();
		showNames = new DefaultComboBoxModel();

		try {
			ResultSet showNameResults = GFXSQL.getResultSet("showName", "*", "");
			while (showNameResults.next()) {
				ShowName currShowName = new ShowName();
				currShowName.fromSQL(showNameResults.getInt("idShowName"));
//				currShowName.idShowName = showNameResults.getInt("idShowName");
//				currShowName.name = showNameResults.getString("name");
//				currShowName.nickName = showNameResults.getString("nickName");
				addShowNameToLists(currShowName);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}


	public static void addShowNameToLists(ShowName newShowName) {
		allShowNames.put(newShowName.getId(), newShowName);
		if(showNames.getSize() > 0){
			showNames.insertElementAt(newShowName, showNames.getSize()-1);
		}else{
			showNames.insertElementAt(newShowName, showNames.getSize());
		}
	}


	public static void addShowNameToSQL(ShowName newShowName) {
		GFXSQL.addShowName(newShowName);
	}
}
